package com.samsung.app;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Message;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class WifiCamChecker
{
  public static final String TAG = "INRY";
  private APChecker mAPCheckerThread = null;
  private final Context mContext;
  private final Handler mHandler;
  private boolean mIsStop = false;

  public WifiCamChecker(Context paramContext, Handler paramHandler)
  {
    this.mContext = paramContext;
    this.mHandler = paramHandler;
  }

  private boolean sendEvent(int paramInt, Object paramObject)
  {
    if (this.mHandler != null)
    {
      Logger.d("INRY", "WifiCamChecker.sendEvent event=" + paramInt);
      Message localMessage = new Message();
      localMessage.what = paramInt;
      localMessage.obj = paramObject;
      this.mHandler.sendMessage(localMessage);
    }
    return false;
  }

  public boolean start()
  {
    Logger.d("INRY", "WifiCamChecker.start");
    stop();
    this.mIsStop = false;
    this.mAPCheckerThread = new APChecker();
    this.mAPCheckerThread.start();
    return true;
  }

  public boolean stop()
  {
    Logger.d("INRY", "WifiCamChecker.stop");
    this.mIsStop = true;
    if (this.mAPCheckerThread != null)
      this.mAPCheckerThread.interrupt();
    try
    {
      this.mAPCheckerThread.join();
      this.mAPCheckerThread = null;
      return true;
    }
    catch (InterruptedException localInterruptedException)
    {
      while (true)
        localInterruptedException.printStackTrace();
    }
  }

  private class APChecker extends Thread
  {
    List<ScanResult> scanResult = new ArrayList();
    WifiManager wifiManager = (WifiManager)WifiCamChecker.this.mContext.getSystemService("wifi");

    public APChecker()
    {
      setName(getClass().getSimpleName());
    }

    private void debugResult(List<ScanResult> paramList)
    {
      Logger.d("INRY", "WifiCamChecker.thread debug scan listCount=" + paramList.size());
      for (int i = 0; ; i++)
      {
        if (i >= paramList.size())
          return;
        ScanResult localScanResult = (ScanResult)paramList.get(i);
        Logger.d("INRY", "WifiCamChecker.thread debug i=" + i + ", ssid=" + localScanResult.SSID);
      }
    }

    private int scanCamAP()throws InterruptedException
    {
      int i = 3;
      int j = 0;
      sleep(1000L);
      this.scanResult.clear();
      ArrayList<String> localArrayList = new ArrayList<String>();
      List<ScanResult> localList;
      while (true)
      {
        if ((WifiCamChecker.this.mIsStop) || (j != 0));
        do
        {
          return this.scanResult.size();
          Logger.d("INRY", "WifiCamChecker.thread scanCamAP 1");
          this.wifiManager.startScan();
          sleep(1000L);
          Logger.d("INRY", "WifiCamChecker.thread scanCamAP 2");
        }
        while (WifiCamChecker.this.mIsStop);
        Logger.d("INRY", "WifiCamChecker.thread scanCamAP 3");
        localList = this.wifiManager.getScanResults();
        if (localList != null)
          break;
        Logger.d("INRY", "WifiCamChecker.thread scanCamAP 4");
      }
      debugResult(localList);
      Logger.d("INRY", "WifiCamChecker.thread scanCamAP 5");
      Iterator localIterator = localList.iterator();
      while (true)
      {
        if (!localIterator.hasNext())
        {
          i--;
          if (i > 0)
            break;
          j = 1;
          break;
        }
        ScanResult localScanResult = (ScanResult)localIterator.next();
        if ((localArrayList.contains(localScanResult.SSID)) || (!Utils.supportDSCPrefix(localScanResult.SSID)))
          continue;
        localArrayList.add(localScanResult.SSID);
        this.scanResult.add(localScanResult);
      }
    }

    private void waitForWifiEnabled()
      throws InterruptedException
    {
      while (true)
      {
        if ((this.wifiManager.isWifiEnabled()) || (WifiCamChecker.this.mIsStop))
          return;
        sleep(500L);
      }
    }

    public void run()
    {
      Logger.d("INRY", "WifiCamChecker.thread start");
      try
      {
        int i = this.wifiManager.getWifiState();
        if ((i == 1) || (i == 0))
        {
          Logger.d("INRY", "WifiCamChecker.thread.wifiEnable(true)");
          this.wifiManager.setWifiEnabled(true);
        }
        Logger.d("INRY", "WifiCamChecker.thread.waitForWifiEnabled >");
        waitForWifiEnabled();
        Logger.d("INRY", "WifiCamChecker.thread.waitForWifiEnabled <");
        Logger.d("INRY", "WifiCamChecker.thread.scanCamAP >");
        int j = scanCamAP();
        Logger.d("INRY", "WifiCamChecker.thread.scanCamAP < Count=" + j);
        WifiCamChecker.this.sendEvent(36, Integer.valueOf(j));
        Logger.d("INRY", "WifiCamChecker.thread end");
        return;
      }
      catch (InterruptedException localInterruptedException)
      {
        while (true)
          WifiCamChecker.this.sendEvent(37, null);
      }
    }
  }
}

/* Location:           C:\Users\Chris\Desktop\viewfinder\com.samsung.app-34_dex2jar.jar
 * Qualified Name:     com.samsung.app.WifiCamChecker
 * JD-Core Version:    0.6.0
 */